/*
 * ADUStartScene.cpp
 *
 *  Created on: May 7, 2014
 *      Author: 01nvchuong
 */

#include "../GameUtils/ADUConstants.h"
#include "ADUStartScene.h"
#include "../GameUtils/ADUGameManager.h"
#include "../GameHeart/ADURoad.h"

CCScene* ADUStartLayer::scene() {

	CCScene *scene = NULL;
	do {
		// scene is an autorelease object
		scene = CCScene::create();
		CC_BREAK_IF(!scene);

		// layer is an autorelease object
		ADUStartLayer *layer = ADUStartLayer::create();
		CC_BREAK_IF(!layer);

		// add layer as child to scene
		scene->addChild(layer);
	} while (0);

	return scene;
}

bool ADUStartLayer::init() {

	bool bRet = false;
	do {
		CC_BREAK_IF(!CCLayer::init());

		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
		// Enable touch/click actions
		this->setTouchEnabled(true);

		// Add Background
		CCSprite* game_background = CCSprite::create(IMG_GAME_BACKGROUND);
		game_background->setPosition(
				ccp(visibleSize.width / 2 + origin.x,
						visibleSize.height / 2 + origin.y));
		this->addChild(game_background, 0);

		// Add Game Title
		CCSprite* game_title = CCSprite::create(IMG_GAME_TITLE);
		float title_X = (visibleSize.width / 2 + origin.x);
		float title_Y = (visibleSize.height * 0.85 + origin.y);
		game_title->setPosition(ccp(title_X + origin.x, title_Y + origin.y));
		this->addChild(game_title, 1);

		// Main menu with 4 items
		/*
		 CCLabelTTF* newGameLabel = CCLabelTTF::create("New Game", MENUITEM_FONT,
		 MENUITEM_FONTSIZE);
		 newGameLabel->setColor(ccc3(255, 255, 255));
		 CCMenuItemLabel* newGameItem = CCMenuItemLabel::create(newGameLabel,
		 this, menu_selector(ADUStartLayer::onNewGameMenuItemClick));

		 CCLabelTTF* optionLabel = CCLabelTTF::create("Option", MENUITEM_FONT,
		 MENUITEM_FONTSIZE);
		 optionLabel->setColor(ccc3(255, 255, 255));
		 CCMenuItemLabel* optionItem = CCMenuItemLabel::create(optionLabel, this,
		 menu_selector(ADUStartLayer::onOptionMenuItemClick));

		 CCLabelTTF* howToPlayLabel = CCLabelTTF::create("How to play",
		 MENUITEM_FONT, MENUITEM_FONTSIZE);
		 howToPlayLabel->setColor(ccc3(255, 255, 255));
		 CCMenuItemLabel* howToPlayItem = CCMenuItemLabel::create(howToPlayLabel,
		 this, menu_selector(ADUStartLayer::onHowToPlayMenuItemClick));

		 CCLabelTTF* aboutLabel = CCLabelTTF::create("About", MENUITEM_FONT,
		 MENUITEM_FONTSIZE);
		 aboutLabel->setColor(ccc3(255, 255, 255));
		 CCMenuItemLabel* aboutItem = CCMenuItemLabel::create(aboutLabel, this,
		 menu_selector(ADUStartLayer::onAboutMenuItemClick));
		 */

		CCMenuItem* newGameItem = CCMenuItemImage::create(IMG_NEWGAME_ITEM,
		IMG_NEWGAME_ITEM, this,
				menu_selector(ADUStartLayer::onNewGameMenuItemClick));

		CCMenuItem* optionItem = CCMenuItemImage::create(IMG_SETTINGS_ITEM,
		IMG_SETTINGS_ITEM, this,
				menu_selector(ADUStartLayer::onSettingMenuItemClick));
		CCMenuItem* highscoreItem = CCMenuItemImage::create(IMG_HIGHSCORES_ITEM,
		IMG_HIGHSCORES_ITEM, this,
				menu_selector(ADUStartLayer::onHighScoreMenuItemClick));
		CCMenuItem* quitItem = CCMenuItemImage::create(IMG_QUIT_ITEM,
		IMG_QUIT_ITEM, this, menu_selector(ADUStartLayer::onQuitMenuItemClick));
		// Combine to form a Menu and allign Vertically
		CCMenu* menu = CCMenu::create(newGameItem, optionItem, highscoreItem,
				quitItem, NULL);
		menu->alignItemsVerticallyWithPadding(20);
		// add this to the layer
		menu->setPosition(
				ccp(visibleSize.width / 2 + origin.x,
						visibleSize.height * 0.4 + origin.y));
		this->addChild(menu, 2);
		bRet = true;
	} while (0);
	return bRet;

	return true;
}

void ADUStartLayer::onNewGameMenuItemClick(CCObject* pSender) {
	ADUGameManager::getInstance()->RunScene(SCENE_GAME);
}

void ADUStartLayer::onSettingMenuItemClick(CCObject* pSender) {

}

void ADUStartLayer::onHighScoreMenuItemClick(CCObject* pSender) {

}

void ADUStartLayer::onQuitMenuItemClick(CCObject* pSender) {

}

